package uk.co.droidinactu.inlibrislibertas.model;

import java.util.ArrayList;
import java.util.HashMap;

import uk.co.droidinactu.common.model.AbstractDataObj;
import android.content.ContentValues;

public class TagEbookLink extends AbstractDataObj {

    /**
     * this number denotes the version of this class. so that we can decide if
     * the structure of this class is the same as the one being deserialized
     * into it
     */
    private static final long serialVersionUID = 1L;

    public static final String DATABASE_TABLE_NAME = "tagEbookLink";
    public static final String FIELD_NAME_TAG_ID = "tag_id";
    public static final String FIELD_NAME_EBOOK_ID = "ebook_id";

    private Long tagId = -1L;
    private Long ebookId = -1L;

    public TagEbookLink() {
    }

    public TagEbookLink(final HashMap<String, String> aRow) {
        super(aRow);
        tagId = Long.parseLong(aRow.get(TagEbookLink.FIELD_NAME_TAG_ID));
        ebookId = Long.parseLong(aRow.get(TagEbookLink.FIELD_NAME_EBOOK_ID));
    }

    public TagEbookLink(final Long tgId, final Long ebkId) {
        tagId = tgId;
        ebookId = ebkId;
    }

    @Override
    public ContentValues getContentValues() {
        final ContentValues map = super.getContentValues();
        map.put(TagEbookLink.FIELD_NAME_TAG_ID, tagId);
        map.put(TagEbookLink.FIELD_NAME_EBOOK_ID, ebookId);
        return map;
    }

    @Override
    public HashMap<Integer, ArrayList<String>> getFields() {
        final HashMap<Integer, ArrayList<String>> fields = super.getFields();

        int x = fields.size();
        fields.put(x++, getArrayList(TagEbookLink.FIELD_NAME_TAG_ID, "Long NOT NULL"));
        fields.put(x++, getArrayList(TagEbookLink.FIELD_NAME_EBOOK_ID, "Long NOT NULL"));
        return fields;
    }

    public String getSqlBooksForTag(final int tgId) {
        return ("select * from " + getTableName() + " where " + TagEbookLink.FIELD_NAME_TAG_ID + "=" + tgId + "");
    }

    public String getSqlTagsForBook(final int bkId) {
        return ("select * from " + getTableName() + " where " + TagEbookLink.FIELD_NAME_EBOOK_ID + "=" + bkId + "");
    }

    public String getSqlUpdateFromV001() {
        // TODO Auto-generated method stub
        return null;
    }

    public String getSqlUpdateFromV002() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getTableName() {
        return DATABASE_TABLE_NAME;
    }

}
